<template>
  <div>
    <!-- 顶部滑动条 -->
    <div id="slider" class="mui-slider">
			<div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
				<div class="mui-scroll">
					<a :class="['mui-control-item', item.id == 0 ? 'mui-active' : '']" v-for="item in cates" :key="item.id" @tap="getPhotoList(item.id)">
						{{item.title}}
					</a>
				</div>
			</div>
		</div>
		<ul class="photo-list">
  		<router-link v-for="item in list" :key="item.id" :to="'/home/photoinfo/' + item.id" tag="li">
    		<img v-lazy="item.img_url">
				<div class="info">
					<h1 class="info-title">{{item.title}}</h1>
					<div class="info-body">{{item.zhaiyao}}</div>
				</div>
  		</router-link>
		</ul>
  </div>
</template>

<script>
import {Toast} from 'mint-ui'
import mui from 'mui/js/mui.min'
export default {
  data () {
    return {
			cates: [],
			list: []
		}
	},
	created () {
		this.getAllCategory()
		this.getPhotoList(0)
	},
	mounted () {
		// 如果要操作元素，最好在 mounted 里面，因为这时候的 DOM 元素是最新的
		// 初始化控件
		mui('.mui-scroll-wrapper').scroll({
			deceleration: 0.0005 // flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
		})
	},
	methods: {
		getAllCategory () {
			this.$http.get('http://www.liulongbin.top:3005/api/getimgcategory').then(result => {
				if (result.body.status === 0) {
					result.body.message.unshift({id: 0, title: '全部'})
					this.cates = result.body.message
				} else {
					Toast('获取分类失败...')
				}
			})
		},
		getPhotoList (cateId) {
			this.$http.get('http://www.liulongbin.top:3005/api/getimages/' + cateId).then(result => {
				if (result.body.status === 0) {
					this.list = result.body.message
				} else {
					Toast('加载图片失败...')
				}
			})
		}
	}
}
</script>

<style lang="scss" scoped>
* {
	touch-action: none;
}
.photo-list{
	list-style: none;
	margin: 0;
	padding: 0 10px;
	li{
		position: relative;
		text-align: center;
		margin-bottom: 10px;
		img{
			width: 100%;
			vertical-align: middle;
		}
		image[lazy=loading] {
  		width: 40px;
  		height: 300px;
  		margin: auto;
		}
	}
}
.info{
	color: #fff;
	background-color: rgba(0, 0, 0, 0.4);
	text-align: left;
	position: absolute;
	bottom: 0;
	max-height: 84px;
	.info-title{
		font-size: 14px;
	}
	.info-body{
		font-size: 13px;
	}
}
</style>
